package drds.data_propagate.sink;

import drds.data_propagate.common.AbstractLifeCycle;
import drds.data_propagate.filter.CanalEventFilter;

import java.util.ArrayList;
import java.util.List;

/**
 * @author jianghang 2012-7-23 下午01:02:45
 */
public abstract class AbstractEventSink<T> extends AbstractLifeCycle implements EventSink<T> {

    protected CanalEventFilter filter;
    protected List<EventDownStreamHandler> handlers = new ArrayList<EventDownStreamHandler>();

    public void addHandler(EventDownStreamHandler handler) {
        this.handlers.add(handler);
    }

    public EventDownStreamHandler getHandler(int index) {
        return this.handlers.get(index);
    }

    public void addHandler(EventDownStreamHandler handler, int index) {
        this.handlers.add(index, handler);
    }

    public void removeHandler(int index) {
        this.handlers.remove(index);
    }

    public void removeHandler(EventDownStreamHandler handler) {
        this.handlers.remove(handler);
    }

    public CanalEventFilter getFilter() {
        return filter;
    }

    public void setFilter(CanalEventFilter filter) {
        this.filter = filter;
    }

    public List<EventDownStreamHandler> getHandlers() {
        return handlers;
    }

    public void interrupt() {
        // do nothing
    }

}
